<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Linksliststotal extends Model
{
    protected $table = 'links_lists_total';
    protected $primaryKey = 'id';

    public static function getLinkListTotal($links_id)
    {
        return self::where("links_id",$links_id)->first();
    }

    public static function createLinkListTotal($links_id)
    {
        return self::insert(["links_id"=>$links_id,"created_at"=>time()]);
    }

    public static function createLinkListTotalBatch($linksListsTotal)
    {
        return self::insert($linksListsTotal);
    }

    public static function updateLinkListTotal($links_id,$page_view,$mini_view,$mini_direct,$mini_press,$mini_card)
    {
        return self::where("links_id",$links_id)->update([
           'page_view' => DB::raw('page_view + '.$page_view),
           'mini_view' => DB::raw('mini_view + '.$mini_view),
           'mini_direct' => DB::raw('mini_direct + '.$mini_direct),
           'mini_press' => DB::raw('mini_press + '.$mini_press),
           'mini_card' => DB::raw('mini_card + '.$mini_card),
        ]);
    }
}
